local EnemyGroup =  require("Controller/EnemyGroup");

EnemyFactory={};
local this = EnemyFactory;
local index = 4;


local spwnPoint = Vector3(0,8,0);
function EnemyFactory.New()
    this.CreateGroup();
end
function EnemyFactory.CreateGroup()
    if (index>4) then
       index=1;
    end
    local name = "EnemyGroup"..index;
    index=index+1;

	resMgr:LoadPrefab("prefabs", {name}, this.LoadOK);   

end
function EnemyFactory.LoadOK(objs)
    local go = newObject(objs[0]);
    go.transform.position=spwnPoint;
    this.curGroup= EnemyGroup.new(go);

    coroutine.start(this.CheckEnmeyCount);
end
function EnemyFactory.CheckEnmeyCount()
    while true do
        coroutine.wait(0.5);
        if (this.curGroup:ChildCount()<=0) then
        this.curGroup:Destroy();
        this.CreateGroup();
        break;
        end
    end 
end